home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / CLEAN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.5 KB  |  53 lines

  1. /* clean.c - strip high-order bits & ctrl chars from text file */
  2. #include "stdio.h"
  3. #include "cminor.h"
  4.  
  5. FILE    *gfopen()   ;
  6.  
  7. main(argc,argv)
  8.   int     argc    ;        /* number of command line words  */
  9.   char    *argv[] ;        /* pointers to each word  */
  10.   {
  11.      int   c  ;
  12.      FILE  *in     ;        /* use this file for input  */
  13.      FILE  *out  ;        /* use this one for output  */
  14.      long  nin    ,  nout  ;    /* counts of chars in and out */
  15.  
  16.      if( argc < 3 )    /* be sure command line has enough words */
  17.     { printf(" USAGE - clean input-file output-file \n");
  18.       exit(1)  ;
  19.     }
  20.  
  21.      in = gfopen(argv[1],"r",ASC_MODE)  ;  /* open input file */
  22.      if(  in == NULL  )
  23.     { printf(" Can't open input file - %s \n",argv[1]) ;
  24.       exit (2) ;
  25.     }
  26.  
  27.      out = gfopen(argv[2],"w",ASC_MODE) ;  /* open output file */
  28.      if( out == NULL  )
  29.     { printf(" Can't open output file - %s \n",argv[2]) ;
  30.       exit (3)  ;
  31.     }
  32.  
  33.      nin   =  0  ;
  34.      nout  =  0  ;
  35.      c       =  getc(in) ;
  36.      while ( c != EOF )     /* get chars until end reached */
  37.     {  nin = nin + 1 ;
  38.        c = c & 127 ;    /* strip high-order bit  */
  39.        /* now see if it is a non-control char   */
  40.        /* or Carriage Return , Line Feed or Tab */
  41.        if(    (  (c >= ' ') && (c <='~')  ) || (c == '\n')
  42.         || (c == '\r') || (c == '\t') || (c == '\f')  )
  43.           { nout  =  nout +1 ; /* good char - output it */
  44.         putc(c,out)  ;
  45.           }
  46.         c  =  getc(in)  ;
  47.     }
  48.      fclose(in)  ;
  49.      fclose(out) ;
  50.      printf(" %10ld characters read \n",nin)  ;
  51.      printf(" %10ld characters written \n",nout)  ;
  52.   }
  53.